<template>
	<view>
		<u-form :model="form" ref="uForm">
			<u-form-item label="用户名"><u-input v-model="form.username" /></u-form-item>
			<u-form-item label="密码"><u-input v-model="form.password" /></u-form-item>
			<u-form-item label="确认密码">
				<u-input type="password" password-icon="true"  />
			</u-form-item>
			<view class="flex-center">
				<u-button type="primary" text="用户登录" @click="dosubmit"></u-button>
			</view>
			
		</u-form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form : {}
			}
		},
		methods: {
			dosubmit(){
				//登录获取openid
				uni.login({
				  provider: 'weixin', //使用微信登录
				  onlyAuthorize:true,
				  success: loginRes=> {
					console.log(loginRes.code);
					uni.request({
						method: 'POST',
					    url: 'http://localhost:33003/auth/shiro/register',
					    data: {
							"username": this.form.username,
							"password": this.form.password,
							"openid":loginRes.code
						},
					    // header: {
					    //     'custom-header': 'hello' //自定义请求头信息
					    // },
					    success: (res) => {
					        uni.switchTab({
					        	url:"/pages/index/index"
					        })
					    }
					});
					
					
				  }
				});

				//注册
				
				//注册成功
				// uni.switchTab({
				// 	url:"/pages/index/index"
				// })
				//can not navigateTo a tabbar page
				// uni.navigateTo({
				// 	url:"/pages/index/index"
				// })
			}
		}
	}
</script>

<style lang="scss">
.flex-center {
	display: flex;
	justify-content: center; /* 水平居中 */
}
</style>
